<?php

/**
 * 列出所有栏目的文档
 *
 * @package    01CMS
 * @subpackage plugin
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

function smarty_block_block ($params, $content, $smarty, &$repeat)
{
    static $category = array();

    if (is_null($content))
    {
        $parentId = isset($params['parentId']) ? $params['parentId'] : 0;
        
        $category = model('Category')->getChildren ($parentId, 0, 1);
    }
    
    if ($o = current($category))
    {
        if ($o->type != 0)
        {
            $o->activeUrl = BOOT_URL . '/data/category/' . $o->id;
            $o->staticUrl = Base::i()->Load->var['htmlSaveDir'] . '/' . $o->alias;
            $o->url = defined('staticHtml') ? $o->staticUrl : $o->activeUrl;
            $smarty->assign('category', $o);
            
            $params['categoryId'] = $o->id;
            if(empty($params['tpl'])){
                $params['tpl'] = 'archiveBlock';
            }
            $data = model('Archive')->getArchives($params);
            Base::i()->archiveBlock = model('Archive')->setArchiveFlag($data);
            $contentBlock = $smarty->fetch($params['tpl'].'.tpl');
            $smarty->assign('archiveBlock', $contentBlock);
        }
        
        next($category);
        
        $repeat = true;
    }
    else
    {
        $repeat = false;
    }
    
    return $content;
}
